﻿using System;
using System.Linq;
using System.Data.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BHXH.LinqRepository;
//using BHXH.Repository;01677614731
using Lists;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using DevExpress.XtraGrid.Views.Grid;
using BHXH.Repository;

namespace BHXH2013.Phieu.PhieuC
{
    public partial class FrmEditPhieuC :  BHXH.Repository.FrmEditPhieu
    {
        bool _SavedOK = true;
        bool _NeedPreventInitNewRow = false;
        bool _NeedCheckDataNullInGridView = false;

        EditState _EditState = EditState.Undefined;
        BHXH.LinqRepository.CauHoiDapAnRepository _repCauhoiDA = new BHXH.LinqRepository.CauHoiDapAnRepository();
        
        ChiTietPhieuRepository _repChiTietPhieu = new ChiTietPhieuRepository();
        CoQuanRepository _repCoQuan = new CoQuanRepository();
        NguoiTraLoiPVRepository _repNguoiTraloiPV = new NguoiTraLoiPVRepository();
        DanhMucPhieuRepository _repPhieu = new DanhMucPhieuRepository();

        //
        List<BHXH.LinqRepository.Phieu_DangBang> lstSource = new List<BHXH.LinqRepository.Phieu_DangBang>();
        //
        //BHXH.Repository.EditState _EditState = BHXH.Repository.EditState.Undefined;
        BHXH.LinqRepository.Phieu _PhieuA = null;
       
        public FrmEditPhieuC()
        {
            InitializeComponent();
        }

        public FrmEditPhieuC(BHXH.LinqRepository.Phieu phieuA)
        {
            InitializeComponent();
            if (phieuA != null)
                _EditState = BHXH.Repository.EditState.Modifying;
            else
                _EditState = BHXH.Repository.EditState.CreatingNew;
            _PhieuA = phieuA;
        }

        protected void SetEditState(BHXH.Repository.EditState editState)
        {
            try
            {
                _EditState = editState;

                base.SetEditState(editState);
                switch (editState)
                {
                    case BHXH.Repository.EditState.CreatingNew:
                    case BHXH.Repository.EditState.Modifying:
                        btnSave.Enabled = true;
                        btnEdit.Enabled = false;
                        btnClose.Enabled = true;
                        //btnLuu.Enabled = true;
                        //btnSua.Enabled = false;
                        //btnDong.Enabled = true;

                        //btnLuu2.Enabled = true;
                        //btnDong2.Enabled = true;
                        //btnSua2.Enabled = false;

                        txtPhuongXa.ReadOnly = false;
                        txtSoNha.ReadOnly = false;
                        txtQuanHuyen.ReadOnly = false;
                        txtTinhThanh.ReadOnly = false;
                        break;
                    case BHXH.Repository.EditState.Saved:
                        btnSave.Enabled = false;
                        btnEdit.Enabled = true;
                        btnClose.Enabled = true;
                        //btnLuu.Enabled = false;
                        //btnSua.Enabled = true;
                        //btnDong.Enabled = true;

                        //btnLuu2.Enabled = false;
                        //btnDong2.Enabled = true;
                        //btnSua2.Enabled = true;

                        txtPhuongXa.ReadOnly = true;
                        txtSoNha.ReadOnly = true;
                        txtQuanHuyen.ReadOnly = true;
                        txtTinhThanh.ReadOnly = true;
                        break;
                }
            }
            catch (Exception ex)
            {
            }
        }



        #region lost focus

        void nmr17_LostFocus(object sender, EventArgs e)
        {
            if (nmr17.Text.Trim() != "5" && nmr17.Text.Trim() != "") nmr18.Focus();
        }
        void nmr18_LostFocus(object sender, EventArgs e)
        {
            if (nmr18.Text.Trim() == "1") nmr20.Focus();
        }
        void nmr19_LostFocus(object sender, EventArgs e)
        {
            if (nmr19.Text.Trim() != "" ) nmr21.Focus();
        }


        void nmr20_LostFocus(object sender, EventArgs e)
        {
            if (nmr20.Text.Trim() != "5" && nmr20.Text.Trim() != "") nmr21.Focus();
        }

        void nmr23_LostFocus(object sender, EventArgs e)
        {
            if (nmr23.Text.Trim() == "4" ) nmr25.Focus();
        }

        void nmr25_LostFocus(object sender, EventArgs e)
        {
            if (nmr25.Text.Trim() != "5" && nmr25.Text.Trim() != "") nmr26.Focus();
        }
        void nmr29_LostFocus(object sender, EventArgs e)
        {
            if (nmr29.Text.Trim() != "5" && nmr29.Text.Trim() != "") nmr30.Focus();
        }

        void nmr33_LostFocus(object sender, EventArgs e)
        {
            if (nmr33.Text.Trim() != "1" && nmr33.Text.Trim() != "") nmr35.Focus();
        }

        void nmr37_LostFocus(object sender, EventArgs e)
        {
            if (nmr37.Text.Trim() != "4" && nmr37.Text.Trim() != "") nmr38.Focus();
        }
        void nmr38_LostFocus(object sender, EventArgs e)
        {
            if (nmr38.Text.Trim() != "4" && nmr38.Text.Trim() != "") nmr39.Focus();
        }

        //void nmr39_LostFocus(object sender, EventArgs e)
        //{
        //    if (nmr39.Text.Trim() != "4" && nmr39.Text.Trim() != "") nmr40.Focus();
        //}


        void nmr40_LostFocus(object sender, EventArgs e)
        {
            if (nmr40.Text.Trim() != "4" && nmr40.Text.Trim() != "") nmr41.Focus();
        }

        void nmr41_LostFocus(object sender, EventArgs e)
        {
            if (nmr41.Text.Trim() != "4" && nmr41.Text.Trim() != "") nmr42.Focus();
        }

        void nmr42_LostFocus(object sender, EventArgs e)
        {
            if (nmr42.Text.Trim() != "3" && nmr42.Text.Trim() != "") nmr43.Focus();
        }

        void nmr43_LostFocus(object sender, EventArgs e)
        {
            if (nmr43.Text.Trim() != "2" && nmr43.Text.Trim() != "") btnSave.Focus();
        }
        #endregion lost focus

        private void FrmEditPhieuC_Load(object sender, EventArgs e)
        {
            try
            {
                lblTitle.Text = "BỘ LAO ĐỘNG -THƯƠNG BINH VÀ XÃ HỘI\nVỤ BẢO HIỂM XÃ HỘI";
                lblLoaiPhieu.Text = "Phiếu C";
                lblDienGiai.Text = "PHIẾU ĐIỀU TRA TÌNH HÌNH THỰC HIỆN LUẬT BHXH ĐỐI VỚI BHXH BẮT BUỘC VÀ BHXH TỰ NGUYỆN NĂM 2013\n " +
                    "(Dành cho người tham gia BHXH tự nguyện)";

                nmr17.LostFocus += new EventHandler(nmr17_LostFocus);
                nmr18.LostFocus += new EventHandler(nmr18_LostFocus);
                nmr19.LostFocus += new EventHandler(nmr19_LostFocus);
                nmr20.LostFocus += new EventHandler(nmr20_LostFocus);
                nmr23.LostFocus += new EventHandler(nmr23_LostFocus);
                nmr25.LostFocus += new EventHandler(nmr25_LostFocus);
                nmr29.LostFocus += new EventHandler(nmr29_LostFocus);
                nmr33.LostFocus += new EventHandler(nmr33_LostFocus);
                nmr37.LostFocus += new EventHandler(nmr37_LostFocus);
                //nmr22.LostFocus += new EventHandler(nmr22_LostFocus);
                nmr38.LostFocus += new EventHandler(nmr38_LostFocus);
                nmr40.LostFocus += new EventHandler(nmr40_LostFocus);
                nmr41.LostFocus += new EventHandler(nmr41_LostFocus);
                nmr42.LostFocus += new EventHandler(nmr42_LostFocus);
                nmr43.LostFocus += new EventHandler(nmr43_LostFocus);
                
                //gridControlB_14.DataSource = dsPhieu_DangBang.PhieuB_Cau14;

                #region Load thông tin phiếu
                if (_PhieuA == null)
                {
                    //_PhieuB = DanhMucPhieu.Instance.NewDoiTuong();
                    SetEditState(EditState.CreatingNew);
                    //Lay gia tri tang dan
                    txtMaPhieu.Text = "C";
                    //phieuObj = new BHXH.LinqRepository.Phieu();
                    _PhieuA = new BHXH.LinqRepository.Phieu();
                }
                else
                {
                    NhanVienDT_GSRepository nhanviendieutraRepository = new NhanVienDT_GSRepository();
                    if (_PhieuA.NVDieuTraID.HasValue)
                    {
                        NhanVienDT_G nhanvienDTG = nhanviendieutraRepository.GetByID(_PhieuA.NVDieuTraID.Value);
                        if (nhanvienDTG != null)
                        {
                            txtDieuTraVien.Text = nhanvienDTG.HoTen;
                        }
                    }

                    txtMaPhieu.Text = _PhieuA.MaPhieu;
                    BHXH.LinqRepository.CoQuan coQuan = _repCoQuan.GetByID(_PhieuA.CoQuanID);
                    
                    dateNgayPV.DateTime = _PhieuA.NgayPV;

                    Lists.NguoiDuocPV nguoiduocpv = Lists.DanhMucNguoiDuocPV.Instance.GetByID(_PhieuA.NguoiTraLoiPVID);
                    if (nguoiduocpv != null)
                    {
                        txtHoTenNguoiDuocPV.Text = nguoiduocpv.HoTen;
                        if (nguoiduocpv.GioiTinh) txtGioiTinh.Text = "1";
                        else txtGioiTinh.Text = "2";
                        numericTexBoxNamSinh.Text = nguoiduocpv.NamSinh.ToString();
                        numericTexBoxTuoiTron.Text = nguoiduocpv.Tuoi.ToString();
                        txtDienThoaiLienHe.Text = nguoiduocpv.DienThoai;
                        txtDanToc.Text = nguoiduocpv.ChucVu;
                    }
                    if (coQuan != null)
                    {
                        txtTenCoQuan.Text = coQuan.Ten;
                        txtTinhThanh.Text = coQuan.Ten;

                       // BHXH.LinqRepository.CoQuan coQuan = new BHXH.LinqRepository.CoQuan();
                        cmbQuanHuyen.EditValue = coQuan.QuanHuyenID;
                        cmbTinhThanh.EditValue = coQuan.TinhID;
                       
                    }

                    BHXH.LinqRepository.ChiTietPhieu ctp = null;

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 5);
                    if (ctp != null)
                    {
                        nmr5.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 5);
                    if (ctp != null)
                    {
                        nmr5.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 6);
                    if (ctp != null)
                    {
                        nmr6.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 7);
                    if (ctp != null)
                    {
                        nmr7.Text = ctp.CauTraLoiFIX1;
                    }


                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 8);
                    if (ctp != null)
                    {
                        nmr8.Text = ctp.CauTraLoiFIX1;
                    }
                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 9);
                    if (ctp != null)
                    {
                        nmr9.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 10);
                    if (ctp != null)
                    {
                        nmr10.Text = ctp.CauTraLoiFIX1;
                    }
                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 11);
                    if (ctp != null)
                    {
                        nmr11.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 12);
                    if (ctp != null)
                    {
                        nmr12.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 13);
                    if (ctp != null)
                    {
                        nmr13.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 14);
                    if (ctp != null)
                    {
                        nmr14.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 15);
                    if (ctp != null)
                    {
                        nmr15.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 16);
                    if (ctp != null)
                    {
                        nmr15.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 17);
                    if (ctp != null)
                    {
                        nmr17.Text = ctp.CauTraLoiFIX1;
                        txtKhac17.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 18);
                    if (ctp != null)
                    {
                        nmr18.Text = ctp.CauTraLoiFIX1;
                       // txtKhac18.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 19);
                    if (ctp != null)
                    {
                        nmr19.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 20);
                    if (ctp != null)
                    {
                        nmr20.Text = ctp.CauTraLoiFIX1;
                        txtKhac20.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 21);
                    if (ctp != null)
                    {
                        nmr21.Text = ctp.CauTraLoiFIX1;
                       
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 22);
                    if (ctp != null)
                    {
                        nrm22_1.Text = ctp.CauTraLoiFIX1;
                        nmr22_2.Text = ctp.CauTraLoiFIX2;
                        
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 23);
                    if (ctp != null)
                    {
                        nmr23.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 24);
                    if (ctp != null)
                    {
                        nmr24.Text = ctp.CauTraLoiFIX1;
                        
                    }


                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 25);
                    if (ctp != null)
                    {
                        nmr25.Text = ctp.CauTraLoiFIX1;
                        txtKhac25.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 26);
                    if (ctp != null)
                    {
                        nmr26.Text = ctp.CauTraLoiFIX1;
                        
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 27);
                    if (ctp != null)
                    {
                        nmr27.Text = ctp.CauTraLoiFIX1;
                        txtKhac27.Text = ctp.CauTraLoiText1;
                    }


                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 28);
                    if (ctp != null)
                    {
                        nmr28.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 29);
                    if (ctp != null)
                    {
                        nmr29.Text = ctp.CauTraLoiFIX1;
                        txtKhac29.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 30);
                    if (ctp != null)
                    {
                        nmr30.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 31);
                    if (ctp != null)
                    {
                        nmr31.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 32);
                    if (ctp != null)
                    {
                        nmr32.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 33);
                    if (ctp != null)
                    {
                        nmr33.Text = ctp.CauTraLoiFIX1;
                        
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 34);
                    if (ctp != null)
                    {
                        nmr34.Text = ctp.CauTraLoiFIX1;
                       
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 35);
                    if (ctp != null)
                    {
                        nmr35.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 36);
                    if (ctp != null)
                    {
                        nmr36.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 37);
                    if (ctp != null)
                    {
                        nmr37.Text = ctp.CauTraLoiFIX1;
                        txtKhac37.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 38);
                    if (ctp != null)
                    {
                        nmr38.Text = ctp.CauTraLoiFIX1;
                        txtKhac38.Text = ctp.CauTraLoiText1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 39);
                    if (ctp != null)
                    {
                        nmr39.Text = ctp.CauTraLoiFIX1;
                        txtKhac39.Text = ctp.CauTraLoiText1;

                        nmr39_2.Text = ctp.CauTraLoiFIX2;
                        nmr39_3.Text = ctp.CauTraLoiFIX3;
                        nmr39_4.Text = ctp.CauTraLoiFIX4;

                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 40);
                    if (ctp != null)
                    {
                        nmr40.Text = ctp.CauTraLoiFIX1;
                        txtKhac40.Text = ctp.CauTraLoiFIX1;
                    }

                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 41);
                    if (ctp != null)
                    {
                        nmr41.Text = ctp.CauTraLoiFIX1;
                        txtKhac41.Text = ctp.CauTraLoiFIX1;
                    }
                    ctp = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 42);
                    if (ctp != null)
                    {
                        nmr42.Text = ctp.CauTraLoiFIX1;
                        txtKhac42.Text = ctp.CauTraLoiFIX1;
                    }

                    SetEditState(EditState.Saved);
                }

                #endregion

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                txtMaPhieu.SelectAll();
                txtMaPhieu.Focus();

            }
        }

        protected void SetCauTraLoiDacBiet(CustomControls.NumericTexBox nmrX, string maTraLoi,
                                           int maCau, int levelTraLoi, System.Windows.Forms.Label lblShow)
        {
            Lists.CauHoi_DA cauHoi_DA = Lists.DanhMucCauHoi_DA.GetByLoaiPhieu_MaCau("PhieuC", maCau, levelTraLoi);
            lblShow.Text = "";
            if (maTraLoi == "") return;
            if (cauHoi_DA != null)
            {
                string[] traloi1 = Regex.Split(cauHoi_DA.TraLoi1, "::");
                if (maTraLoi.Contains(traloi1[0].Trim()))
                    if (traloi1.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi1[1].Trim();
                string[] traloi2 = Regex.Split(cauHoi_DA.TraLoi2, "::");
                if (maTraLoi.Contains(traloi2[0].Trim()))
                    if (traloi2.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi2[1].Trim();
                string[] traloi3 = Regex.Split(cauHoi_DA.TraLoi3, "::");
                if (maTraLoi.Contains(traloi3[0].Trim()))
                    if (traloi3.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi3[1].Trim();
                string[] traloi4 = Regex.Split(cauHoi_DA.TraLoi4, "::");
                if (maTraLoi.Contains(traloi4[0].Trim()))
                    if (traloi4.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi4[1].Trim();
                string[] traloi5 = Regex.Split(cauHoi_DA.TraLoi5, "::");
                if (maTraLoi.Contains(traloi5[0].Trim()))
                    if (traloi5.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi5[1].Trim();
                string[] traloi6 = Regex.Split(cauHoi_DA.TraLoi6, "::");
                if (maTraLoi.Contains(traloi6[0].Trim()))
                    if (traloi6.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi6[1].Trim();
                string[] traloi7 = Regex.Split(cauHoi_DA.TraLoi7, "::");
                if (maTraLoi.Contains(traloi7[0].Trim()))
                    if (traloi7.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi7[1].Trim();
                string[] traloi8 = Regex.Split(cauHoi_DA.TraLoi8, "::");
                if (maTraLoi.Contains(traloi8[0].Trim()))
                    if (traloi8.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi8[1].Trim();
                string[] traloi9 = Regex.Split(cauHoi_DA.TraLoi9, "::");
                if (maTraLoi.Contains(traloi9[0].Trim()))
                    if (traloi9.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi9[1].Trim();
                string[] traloi10 = Regex.Split(cauHoi_DA.TraLoi10, "::");
                if (maTraLoi.Contains(traloi10[0].Trim()))
                    if (traloi10.Length >= 2) lblShow.Text = lblShow.Text + ", " + traloi10[1].Trim();
            }

            if (lblShow.Text == "" && nmrX.Text != "0")
            {
                MessageBox.Show("Không có trong danh mục câu trả lời.\nBạn cần nhập lại");
                nmrX.Text = "";
                nmrX.Focus();
            }
        }
        protected void SetCauTraLoi(CustomControls.NumericTexBox nmrX, string loaiPhieu, string maTraLoi, int maCau, int levelTraLoi, System.Windows.Forms.Label lblShow)
        {
            //Lists.CauHoi_DA cauHoi_DA = Lists.DanhMucCauHoi_DA.GetByLoaiPhieu_MaCau(loaiPhieu, maCau, levelTraLoi);
            
            BHXH.LinqRepository.CauHoi_DA cauHoi_DA = _repCauhoiDA.GetByLoaiPhieu_MaCau(loaiPhieu, maCau, levelTraLoi);
            lblShow.Text = "";
            if (maTraLoi == "") return;
            if (cauHoi_DA != null)
            {
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi1))
                {
                    string[] traloi1 = Regex.Split(cauHoi_DA.TraLoi1, "::");
                    if (maTraLoi == traloi1[0])
                        lblShow.Text = traloi1[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi2))
                {
                    string[] traloi2 = Regex.Split(cauHoi_DA.TraLoi2, "::");
                    if (maTraLoi == traloi2[0])
                        lblShow.Text = traloi2[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi3))
                {
                    string[] traloi3 = Regex.Split(cauHoi_DA.TraLoi3, "::");
                    if (maTraLoi == traloi3[0])
                        lblShow.Text = traloi3[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi4))
                {
                    string[] traloi4 = Regex.Split(cauHoi_DA.TraLoi4, "::");
                    if (maTraLoi == traloi4[0])
                        lblShow.Text = traloi4[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi5))
                {
                    string[] traloi5 = Regex.Split(cauHoi_DA.TraLoi5, "::");
                    if (maTraLoi == traloi5[0])
                        lblShow.Text = traloi5[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi6))
                {
                    string[] traloi6 = Regex.Split(cauHoi_DA.TraLoi6, "::");
                    if (maTraLoi == traloi6[0])
                        lblShow.Text = traloi6[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi7))
                {
                    string[] traloi7 = Regex.Split(cauHoi_DA.TraLoi7, "::");
                    if (maTraLoi == traloi7[0])
                        lblShow.Text = traloi7[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi8))
                {
                    string[] traloi8 = Regex.Split(cauHoi_DA.TraLoi8, "::");
                    if (maTraLoi == traloi8[0])
                        lblShow.Text = traloi8[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi9))
                {
                    string[] traloi9 = Regex.Split(cauHoi_DA.TraLoi9, "::");
                    if (maTraLoi == traloi9[0])
                        lblShow.Text = traloi9[1];
                }
                if (!string.IsNullOrEmpty(cauHoi_DA.TraLoi10))
                {
                    string[] traloi10 = Regex.Split(cauHoi_DA.TraLoi10, "::");
                    if (maTraLoi == traloi10[0])
                        lblShow.Text = traloi10[1];
                }
            }

            if (lblShow.Text == "" && nmrX.Text != "0")
            {
                MessageBox.Show("Không có trong danh mục câu trả lời.\nBạn cần nhập lại");
                nmrX.Text = "";
                nmrX.Focus();
            }
        }

        private void txtGioiTinh_TextChanged(object sender, EventArgs e)
        {

        }

        private void nmr5_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr5.Text.Trim();
            SetCauTraLoi(nmr5, "PhieuC", maTraLoi, 5, 0, tl5);
        }

        private void nmr6_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr6.Text.Trim();
            SetCauTraLoi(nmr6, "PhieuC", maTraLoi, 6, 0, tl6);
        }

        private void nmr7_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr7.Text.Trim();
            SetCauTraLoi(nmr7, "PhieuC", maTraLoi, 7, 0, tl7);
        }

        private void nmr8_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr8.Text.Trim();
            SetCauTraLoi(nmr8, "PhieuC", maTraLoi, 8, 0, tl8);
        }

        private void nmr9_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr9.Text.Trim();
            SetCauTraLoi(nmr9, "PhieuC", maTraLoi, 9, 0, tl9);
        }

        private void nmr10_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr10.Text.Trim();
            SetCauTraLoi(nmr10, "PhieuC", maTraLoi, 10, 0, tl10);
        }

        private void nmr11_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr11.Text.Trim();
            SetCauTraLoi(nmr11, "PhieuC", maTraLoi, 11, 0, tl11);
        }

        private void nmr12_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr7.Text.Trim();
            SetCauTraLoi(nmr12, "PhieuC", maTraLoi, 12, 0, tl12);
        }

        private void nmr13_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr13.Text.Trim();
            SetCauTraLoi(nmr13, "PhieuC", maTraLoi, 13, 0, tl13);
        }

        private void nmr14_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr14.Text.Trim();
            SetCauTraLoi(nmr14, "PhieuC", maTraLoi, 14, 0, tl14);
        }

        private void nmr15_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr15.Text.Trim();
            SetCauTraLoi(nmr15, "PhieuC", maTraLoi, 15, 0, tl15);
        }

        private void nmr16_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr16.Text.Trim();
            SetCauTraLoi(nmr16, "PhieuC", maTraLoi, 16, 0, tl16);
        }

        private void nmr17_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr17.Text.Trim();
            //SetCauTraLoi(nmr17, "PhieuC", maTraLoi, 17, 0, tl7);
            SetCauTraLoiDacBiet(nmr17, maTraLoi, 17, 0, tl17);
        }

        private void nmr18_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr18.Text.Trim();
            SetCauTraLoi(nmr18, "PhieuC", maTraLoi, 18, 0, tl18);
        }

        private void nmr19_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr19.Text.Trim();
            SetCauTraLoi(nmr19, "PhieuC", maTraLoi, 19, 0, tl19);
        }

        private void nmr20_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr20.Text.Trim();
            //SetCauTraLoi(nmr20, "PhieuC", maTraLoi, 20, 0, tl20);
            SetCauTraLoiDacBiet(nmr20, maTraLoi, 20, 0, tl20);
        }

        private void nmr21_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void nmr23_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr23.Text.Trim();
           // SetCauTraLoi(nmr23, "PhieuC", maTraLoi, 23, 0, tl23);
            SetCauTraLoiDacBiet(nmr23, maTraLoi, 23, 0, tl23);
        }

        private void nmr24_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void nmr25_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr25.Text.Trim();
            //SetCauTraLoi(nmr25, "PhieuC", maTraLoi, 25, 0, tl25);
            SetCauTraLoiDacBiet(nmr25, maTraLoi, 25, 0, tl25);
        }

        private void nmr26_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr26.Text.Trim();
            SetCauTraLoi(nmr26, "PhieuC", maTraLoi, 26, 0, tl26);
        }

        private void nmr27_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr27.Text.Trim();
            //SetCauTraLoi(nmr27, "PhieuC", maTraLoi, 20, 0, tl27);
            SetCauTraLoiDacBiet(nmr27, maTraLoi, 27, 0, tl27);
        }

        private void nmr28_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr28.Text.Trim();
            SetCauTraLoi(nmr28, "PhieuC", maTraLoi, 28, 0, tl28);
        }

        private void nmr29_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr29.Text.Trim();
            //SetCauTraLoi(nmr29, "PhieuC", maTraLoi, 29, 0, tl29);
           // SetCauTraLoiDacBiet(nmr29, "PhieuC", maTraLoi, 29,
            SetCauTraLoiDacBiet(nmr29, maTraLoi, 29, 0, tl29);
        }

        private void nmr30_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr30.Text.Trim();
            SetCauTraLoi(nmr30, "PhieuC", maTraLoi, 30, 0, tl30);
        }

        private void nmr31_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr31.Text.Trim();
            SetCauTraLoi(nmr31, "PhieuC", maTraLoi, 31, 0, tl31);
        }

        private void nmr32_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr32.Text.Trim();
            SetCauTraLoi(nmr32, "PhieuC", maTraLoi, 32, 0, tl32);
        }

        private void nmr33_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr33.Text.Trim();
            SetCauTraLoi(nmr33, "PhieuC", maTraLoi, 33, 0, tl33);
        }

        private void nmr34_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr34.Text.Trim();
            SetCauTraLoi(nmr34, "PhieuC", maTraLoi, 34, 0, tl34);
        }

        private void nmr35_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr35.Text.Trim();
            SetCauTraLoi(nmr35, "PhieuC", maTraLoi, 35, 0, tl35);
        }

        private void nmr36_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr36.Text.Trim();
            SetCauTraLoi(nmr36, "PhieuC", maTraLoi, 36, 0, tl36);
        }

        private void nmr37_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr37.Text.Trim();
            SetCauTraLoi(nmr37, "PhieuC", maTraLoi, 37, 0, tl37);
        }

        private void nmr38_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr38.Text.Trim();
            SetCauTraLoi(nmr38, "PhieuC", maTraLoi, 38, 0, tl38);
        }

        private void nmr39_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr39.Text.Trim();
            SetCauTraLoi(nmr39, "PhieuC", maTraLoi, 39, 0, tl39);
        }

        private void nmr40_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr40.Text.Trim();
            SetCauTraLoi(nmr40, "PhieuC", maTraLoi, 40, 0, tl40);
        }

        private void nmr41_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr41.Text.Trim();
            SetCauTraLoi(nmr41, "PhieuC", maTraLoi, 41, 0, tl41);
        }

        private void nmr42_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr42.Text.Trim();
            SetCauTraLoi(nmr42, "PhieuC", maTraLoi, 42, 0, tl42);
        }

        private void nmr43_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr43.Text.Trim();
            SetCauTraLoi(nmr43, "PhieuC", maTraLoi, 43, 0, tl43);
        }


        /// <summary>
        /// Save data
        /// </summary>
        protected override void Save()
        {
            try
            {
                CheckFullInfo();
                try
                {
                    BHXH.LinqRepository.Phieu phieuA = new BHXH.LinqRepository.Phieu();
                    if (_EditState == BHXH.Repository.EditState.CreatingNew)    //mỗi phiếu tạo mới là 1 người được PV mới
                    {

                        NhanVienDT_G nhanvienDTGS = new NhanVienDT_G();
                        nhanvienDTGS.HoTen = txtDieuTraVien.Text;

                        NhanVienDT_GSRepository dieutravienRepository = new NhanVienDT_GSRepository();
                        dieutravienRepository.InsertOne(nhanvienDTGS);
                        dieutravienRepository.SubmitChanges();
                        phieuA.NVDieuTraID = nhanvienDTGS.ID;

                        NguoiTraLoiPV nguoitraloi = new NguoiTraLoiPV();
                        nguoitraloi.HoTen = txtHoTenNguoiDuocPV.Text.Trim();
                        if (txtGioiTinh.Text == "1") nguoitraloi.GioiTinh = true;
                        else nguoitraloi.GioiTinh = false;

                        nguoitraloi.NamSinh = Convert.ToInt32(numericTexBoxNamSinh.Text.Trim());
                        nguoitraloi.Tuoi = Convert.ToInt32(numericTexBoxTuoiTron.Text.Trim());
                        //nguoitraloi.ChucVu = txtChucVu.Text.Trim();
                      //  nguoitraloi.DienThoai = txtDienThoaiLienHe.Text.Trim();
                        nguoitraloi.ChucVu = txtDanToc.Text;

                        //nguoitraloi.ID = Guid.NewGuid();
                        _repNguoiTraloiPV.InsertOne(nguoitraloi);
                        _repNguoiTraloiPV.SubmitChanges();
                        //
                        BHXH.LinqRepository.CoQuan coQuan = new BHXH.LinqRepository.CoQuan();
                        coQuan.Ten = txtTinhThanh.Text;
                        coQuan.TinhID = (Guid)cmbTinhThanh.EditValue;
                        coQuan.QuanHuyenID = (Guid)cmbQuanHuyen.EditValue;
                        //coQuan.PhuongXa = txtPhuongXa.Text.Trim();
                        //coQuan.Sonha_Pho = txtSoNha.Text.Trim();

                        _repCoQuan.InsertOne(coQuan);
                        _repCoQuan.SubmitChanges();
                        //
                        #region Phieu
                        phieuA.MaPhieu = "C" + txtMaPhieu.Text.Trim().Replace("C", "");
                        phieuA.LoaiPhieu = "PhieuC";
                        //phieuA.CoQuan = coQuan;
                        phieuA.NgayPV = dateNgayPV.DateTime;
                        
                        // phieuA.NguoiTraLoiPV = nguoitraloi;

                        phieuA.CoQuanID = coQuan.ID;
                        phieuA.NguoiTraLoiPVID = nguoitraloi.ID;
                        #endregion

                        _repPhieu.InsertOne(phieuA);
                        _repPhieu.SubmitChanges();

                    }
                    else
                    {

                        var nguoiDuocPV = _repNguoiTraloiPV.GetById(_PhieuA.NguoiTraLoiPVID);
                        nguoiDuocPV.HoTen = txtHoTenNguoiDuocPV.Text.Trim();
                        if (txtGioiTinh.Text == "1") nguoiDuocPV.GioiTinh = true;
                        else nguoiDuocPV.GioiTinh = false;
                        nguoiDuocPV.NamSinh = Convert.ToInt32(numericTexBoxNamSinh.Text.Trim());
                        nguoiDuocPV.Tuoi = Convert.ToInt32(numericTexBoxTuoiTron.Text.Trim());
                        // nguoiDuocPV.ChucVu = txtChucVu.Text.Trim();
                        nguoiDuocPV.DienThoai = txtDienThoaiLienHe.Text.Trim();

                       // nguoipv = nguoiDuocPV;
                        _repNguoiTraloiPV.EditOne(nguoiDuocPV);
                        //
                        // _repCoQuan.GetById
                        var coQuan = _repCoQuan.GetByID(_PhieuA.CoQuanID);
                        coQuan.Ten = txtTinhThanh.Text.Trim();
                        coQuan.TinhID = (Guid)cmbTinhThanh.EditValue;
                        coQuan.QuanHuyenID = (Guid)cmbQuanHuyen.EditValue;
                        //coQuan.PhuongXa = txtPhuongXa.Text.Trim();
                        //coQuan.Sonha_Pho = txtSoNha.Text.Trim();
                        _repCoQuan.EditOne(coQuan);
                        //
                        phieuA = _repPhieu.GetOneById(_PhieuA.ID);

                        #region Phieu
                        phieuA.MaPhieu = "C" + txtMaPhieu.Text.Trim().Replace("C", "");
                        phieuA.LoaiPhieu = "PhieuC";
                        // phieuA.CoQuan = coQuan;
                        phieuA.NgayPV = dateNgayPV.DateTime;
                        phieuA.NguoiTraLoiPVID = nguoiDuocPV.ID;
                        #endregion

                    }
                    //  _repPhieu.SubmitChanges();

                    #region Phieu Dang Bang

                    //InsertOrUpdateToDB(phieuA, source12, 12);

                    #endregion

                    #region chi tiết phiếu


                    BHXH.LinqRepository.ChiTietPhieu chiTietPhieu;
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 5);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr5.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 5;
                        chiTietPhieu.CauTraLoiFIX1 = nmr5.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 6);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr6.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 6;
                        chiTietPhieu.CauTraLoiFIX1 = nmr6.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 7);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr7.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 7;
                        chiTietPhieu.CauTraLoiFIX1 = nmr7.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 8);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr8.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 8;
                        chiTietPhieu.CauTraLoiFIX1 = nmr8.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //10
                    //ChiTietPhieu chiTietPhieu;
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 9);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr9.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 9;
                        chiTietPhieu.CauTraLoiFIX1 = nmr9.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //10
                    //ChiTietPhieu chiTietPhieu;
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 10);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr10.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 10;
                        chiTietPhieu.CauTraLoiFIX1 = nmr10.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //11

                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 11);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr11.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 11;
                        chiTietPhieu.CauTraLoiFIX1 = nmr11.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //12 là grid
                    //11

                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 12);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr12.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 12;
                        chiTietPhieu.CauTraLoiFIX1 = nmr12.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //13
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 13);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr13.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 13;
                        chiTietPhieu.CauTraLoiFIX1 = nmr13.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //14
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 14);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr14.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 14;
                        chiTietPhieu.CauTraLoiFIX1 = nmr14.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //15
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 15);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr15.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 15;
                        chiTietPhieu.CauTraLoiFIX1 = nmr15.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                   
                    //16
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 16);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr16.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 16;
                        chiTietPhieu.CauTraLoiFIX1 = nmr16.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                   

                    //17
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 17);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr17.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac17.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 17;
                        chiTietPhieu.CauTraLoiFIX1 = nmr17.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac17.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //18
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 18);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr18.Text;
                      //  chiTietPhieu.CauTraLoiText1 = txtKhac18.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 18;
                        chiTietPhieu.CauTraLoiFIX1 = nmr18.Text;
                       // chiTietPhieu.CauTraLoiText1 = txtKhac18.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                   


                    //19
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 19);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr19.Text;
                        // chiTietPhieu.CauTraLoiText1 = txtKhac18.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 19;
                        chiTietPhieu.CauTraLoiFIX1 = nmr19.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //20
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 20);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr20.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac20.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 20;
                        chiTietPhieu.CauTraLoiFIX1 = nmr20.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac20.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }



                    //21
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 21);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr21.Text;
                       // chiTietPhieu.CauTraLoiText1 = txtKhac21.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 21;
                        chiTietPhieu.CauTraLoiFIX1 = nmr21.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac21.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    //22
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 22);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nrm22_1.Text;
                        chiTietPhieu.CauTraLoiFIX2 = nmr22_2.Text;
                        
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 22;
                        chiTietPhieu.CauTraLoiFIX1 = nrm22_1.Text;
                        chiTietPhieu.CauTraLoiFIX2 = nmr22_2.Text;
                        
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //23
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 23);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr23.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac23.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 23;
                        chiTietPhieu.CauTraLoiFIX1 = nmr23.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac22.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //24
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 24);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr24.Text;
                       // chiTietPhieu.CauTraLoiText1 = txtKhac24.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 24;
                        chiTietPhieu.CauTraLoiFIX1 = nmr24.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac24.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //25
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 25);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr25.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 25;
                        chiTietPhieu.CauTraLoiFIX1 = nmr25.Text;
                          chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //26
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 26);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr26.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac26.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 26;
                        chiTietPhieu.CauTraLoiFIX1 = nmr26.Text;
                      //  chiTietPhieu.CauTraLoiText1 = txtKhac26.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //27
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 27);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr27.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac27.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 27;
                        chiTietPhieu.CauTraLoiFIX1 = nmr27.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac27.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //28
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 28);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr28.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 28;
                        chiTietPhieu.CauTraLoiFIX1 = nmr28.Text;
                        //  chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }
                    //29
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 29);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr29.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac29.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 29;
                        chiTietPhieu.CauTraLoiFIX1 = nmr29.Text;
                          chiTietPhieu.CauTraLoiText1 = txtKhac29.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //30
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 30);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr30.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 30;
                        chiTietPhieu.CauTraLoiFIX1 = nmr30.Text;
                        //  chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    //31
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 31);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr31.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 31;
                        chiTietPhieu.CauTraLoiFIX1 = nmr31.Text;
                        //  chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //32
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 32);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr32.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 32;
                        chiTietPhieu.CauTraLoiFIX1 = nmr32.Text;
                        //  chiTietPhieu.CauTraLoiText1 = txtKhac25.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //33
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 33);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr33.Text;
                       // chiTietPhieu.CauTraLoiText1 = txtKhac33.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 33;
                        chiTietPhieu.CauTraLoiFIX1 = nmr33.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac33.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //34
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 34);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr34.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac34.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 34;
                        chiTietPhieu.CauTraLoiFIX1 = nmr34.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac34.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    //35
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 35);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr35.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac35.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 35;
                        chiTietPhieu.CauTraLoiFIX1 = nmr35.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac34.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //36
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 36);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr36.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac35.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 36;
                        chiTietPhieu.CauTraLoiFIX1 = nmr36.Text;
                        //chiTietPhieu.CauTraLoiText1 = txtKhac34.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //37
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 37);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr37.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac37.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 37;
                        chiTietPhieu.CauTraLoiFIX1 = nmr37.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac37.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //38
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 38);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr38.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac38.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 38;
                        chiTietPhieu.CauTraLoiFIX1 = nmr38.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac38.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //39
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 39);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr39.Text;
                        chiTietPhieu.CauTraLoiFIX2 = nmr39_2.Text;
                        chiTietPhieu.CauTraLoiFIX3 = nmr39_3.Text;
                        chiTietPhieu.CauTraLoiFIX4 = nmr39_4.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac39.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 39;
                        
                        chiTietPhieu.CauTraLoiFIX1 = nmr39.Text;
                        chiTietPhieu.CauTraLoiFIX2 = nmr39_2.Text;
                        chiTietPhieu.CauTraLoiFIX3 = nmr39_3.Text;
                        chiTietPhieu.CauTraLoiFIX4 = nmr39_4.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac39.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //40
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 40);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr40.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac40.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 40;
                        chiTietPhieu.CauTraLoiFIX1 = nmr40.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac40.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //41
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 41);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr41.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac41.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 41;
                        chiTietPhieu.CauTraLoiFIX1 = nmr41.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac41.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    //42
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 42);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr42.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac42.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 42;
                        chiTietPhieu.CauTraLoiFIX1 = nmr42.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac42.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }


                    //43
                    chiTietPhieu = _repChiTietPhieu.GetByPhieuID_MaCau(_PhieuA.ID, 43);
                    if (chiTietPhieu != null)
                    {
                        chiTietPhieu.CauTraLoiFIX1 = nmr43.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac43.Text;
                        _repChiTietPhieu.EditOne(chiTietPhieu);
                    }
                    else
                    {
                        chiTietPhieu = new BHXH.LinqRepository.ChiTietPhieu();
                        chiTietPhieu.PhieuID = phieuA.ID;
                        chiTietPhieu.MaCau = 43;
                        chiTietPhieu.CauTraLoiFIX1 = nmr43.Text;
                        chiTietPhieu.CauTraLoiText1 = txtKhac43.Text;
                        _repChiTietPhieu.InsertOne(chiTietPhieu);
                    }

                    _repChiTietPhieu.SubmitChanges();
                    #endregion

                   
                    SetEditState(EditState.Saved);
                    //transaction.Commit();
                    _SavedOK = true;
                }
                catch (Exception ex)
                {
                    //transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    //con.Close();
                    txtMaPhieu.Focus();
                }
            }
            catch (Exception ex)
            {
                _SavedOK = false;
                BHXH.Repository.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            Edit();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtTinhThanh_TextChanged(object sender, EventArgs e)
        {

        }

        private void nmr39_2_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr39_2.Text.Trim();
            SetCauTraLoi(nmr39_2, "PhieuC", maTraLoi, 39, 0, tl39_2);
        }

        private void nmr39_3_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr39.Text.Trim();
            SetCauTraLoi(nmr39_3, "PhieuC", maTraLoi, 39, 0, tl39_3);
        }

        private void nmr39_4_TextChanged(object sender, EventArgs e)
        {
            string maTraLoi = nmr39_4.Text.Trim();
            SetCauTraLoi(nmr39_4, "PhieuC", maTraLoi, 39, 0, tl39_4);
        }

      
       
    }
}
